package com.esri.core.geometry;

import com.github.mikephil.charting.utils.Utils;
import java.nio.ByteBuffer;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class AttributeStreamOfFloat extends AttributeStreamBase {
    float[] a;
    int b;

    @Override // com.esri.core.geometry.AttributeStreamBase
    public int getPersistence() {
        return 0;
    }

    public int size() {
        return this.b;
    }

    public void reserve(int i) {
        if (i <= 0) {
            return;
        }
        float[] fArr = this.a;
        if (fArr == null) {
            this.a = new float[i];
        } else if (i <= fArr.length) {
        } else {
            float[] fArr2 = new float[i];
            System.arraycopy(fArr, 0, fArr2, 0, this.b);
            this.a = fArr2;
        }
    }

    public AttributeStreamOfFloat(int i) {
        this.a = null;
        this.a = new float[i >= 2 ? i : 2];
        this.b = i;
    }

    public AttributeStreamOfFloat(int i, float f) {
        this.a = null;
        this.a = new float[i >= 2 ? i : 2];
        this.b = i;
        for (int i2 = 0; i2 < i; i2++) {
            this.a[i2] = f;
        }
    }

    public AttributeStreamOfFloat(AttributeStreamOfFloat attributeStreamOfFloat) {
        this.a = null;
        this.a = (float[]) attributeStreamOfFloat.a.clone();
        this.b = attributeStreamOfFloat.b;
    }

    public AttributeStreamOfFloat(AttributeStreamOfFloat attributeStreamOfFloat, int i) {
        this.a = null;
        int size = attributeStreamOfFloat.size();
        i = size <= i ? size : i;
        float[] fArr = new float[i >= 2 ? i : 2];
        this.a = fArr;
        System.arraycopy(attributeStreamOfFloat.a, 0, fArr, 0, i);
    }

    public float read(int i) {
        return this.a[i];
    }

    public void write(int i, float f) {
        if (this.m_bReadonly) {
            throw new RuntimeException("invalid_call");
        }
        this.a[i] = f;
    }

    public void add(float f) {
        resize(this.b + 1);
        this.a[this.b - 1] = f;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public AttributeStreamBase restrictedClone(int i) {
        int i2 = this.b;
        if (i >= i2) {
            i = i2;
        }
        float[] fArr = new float[i];
        System.arraycopy(this.a, 0, fArr, 0, i);
        this.a = fArr;
        this.b = i;
        return this;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public int virtualSize() {
        return size();
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public double readAsDbl(int i) {
        return read(i);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public int readAsInt(int i) {
        return (int) read(i);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public long readAsInt64(int i) {
        return read(i);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void resize(int i) {
        if (this.m_bLockedInSize) {
            throw new GeometryException("invalid call. Attribute Stream is locked and cannot be resized.");
        }
        if (i <= this.b) {
            int i2 = (i * 5) / 4;
            float[] fArr = this.a;
            if (i2 < fArr.length) {
                float[] fArr2 = new float[i];
                System.arraycopy(fArr, 0, fArr2, 0, i);
                this.a = fArr2;
            }
            this.b = i;
            return;
        }
        if (i > this.a.length) {
            float[] fArr3 = new float[i < 64 ? Math.max(i * 2, 4) : (i * 5) / 4];
            System.arraycopy(this.a, 0, fArr3, 0, this.b);
            this.a = fArr3;
        }
        this.b = i;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void resizePreserveCapacity(int i) {
        float[] fArr = this.a;
        if (fArr == null || i > fArr.length) {
            resize(i);
        }
        if (this.m_bLockedInSize) {
            throw new GeometryException("invalid call. Attribute Stream is locked and cannot be resized.");
        }
        this.b = i;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void resize(int i, double d) {
        if (this.m_bLockedInSize) {
            throw new GeometryException("invalid call. Attribute Stream is locked and cannot be resized.");
        }
        if (i <= this.b) {
            int i2 = (i * 5) / 4;
            float[] fArr = this.a;
            if (i2 < fArr.length) {
                float[] fArr2 = new float[i];
                System.arraycopy(fArr, 0, fArr2, 0, i);
                this.a = fArr2;
            }
            this.b = i;
            return;
        }
        if (i > this.a.length) {
            float[] fArr3 = new float[i < 64 ? Math.max(i * 2, 4) : (i * 5) / 4];
            System.arraycopy(this.a, 0, fArr3, 0, this.b);
            this.a = fArr3;
        }
        for (int i3 = this.b; i3 < i; i3++) {
            this.a[i3] = (float) d;
        }
        this.b = i;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void writeAsDbl(int i, double d) {
        write(i, (float) d);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void writeAsInt64(int i, long j) {
        write(i, (float) j);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void writeAsInt(int i, int i2) {
        write(i, i2);
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public int calculateHashImpl(int i, int i2, int i3) {
        int size = size();
        while (i2 < size && i2 < i3) {
            i = NumberUtils.hash(i, read(i2));
            i2++;
        }
        return i;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public boolean equals(AttributeStreamBase attributeStreamBase, int i, int i2) {
        if (attributeStreamBase != null && (attributeStreamBase instanceof AttributeStreamOfFloat)) {
            AttributeStreamOfFloat attributeStreamOfFloat = (AttributeStreamOfFloat) attributeStreamBase;
            int size = size();
            int size2 = attributeStreamOfFloat.size();
            if (i2 > size || (i2 > size2 && size != size2)) {
                return false;
            }
            if (i2 > size) {
                i2 = size;
            }
            while (i < i2) {
                if (read(i) != attributeStreamOfFloat.read(i)) {
                    return false;
                }
                i++;
            }
            return true;
        }
        return false;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void addRange(AttributeStreamBase attributeStreamBase, int i, int i2, boolean z, int i3) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        if (!z && (i3 < 1 || i2 % i3 != 0)) {
            throw new IllegalArgumentException();
        }
        int i4 = this.b;
        resize(i4 + i2);
        if (z) {
            System.arraycopy(((AttributeStreamOfDbl) attributeStreamBase).a, i, this.a, i4, i2);
            return;
        }
        int i5 = i2;
        int i6 = 0;
        while (i6 < i2) {
            i5 -= i3;
            for (int i7 = 0; i7 < i3; i7++) {
                this.a[i4 + i6 + i7] = ((AttributeStreamOfFloat) attributeStreamBase).a[i + i5 + i7];
            }
            i6 += i3;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void insertRange(int i, AttributeStreamBase attributeStreamBase, int i2, int i3, boolean z, int i4, int i5) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        if (!z && (i4 < 1 || i3 % i4 != 0)) {
            throw new IllegalArgumentException();
        }
        float[] fArr = this.a;
        System.arraycopy(fArr, i, fArr, i + i3, i5 - i);
        float[] fArr2 = this.a;
        AttributeStreamOfFloat attributeStreamOfFloat = (AttributeStreamOfFloat) attributeStreamBase;
        float[] fArr3 = attributeStreamOfFloat.a;
        if (fArr2 == fArr3 && i < i2) {
            i2 += i3;
        }
        if (z) {
            System.arraycopy(fArr3, i2, fArr2, i, i3);
            return;
        }
        int i6 = i3;
        int i7 = 0;
        while (i7 < i3) {
            i6 -= i4;
            for (int i8 = 0; i8 < i4; i8++) {
                this.a[i + i7 + i8] = attributeStreamOfFloat.a[i2 + i6 + i8];
            }
            i7 += i4;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void insertRange(int i, double d, int i2, int i3) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        float[] fArr = this.a;
        System.arraycopy(fArr, i, fArr, i + i2, i3 - i);
        float f = (float) d;
        for (int i4 = 0; i4 < i2; i4++) {
            this.a[i + i4] = f;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void insertAttributes(int i, Point point, int i2, int i3) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        int componentCount = VertexDescription.getComponentCount(i2);
        float[] fArr = this.a;
        System.arraycopy(fArr, i, fArr, i + componentCount, i3 - i);
        for (int i4 = 0; i4 < componentCount; i4++) {
            this.a[i + i4] = (float) point.a(i2, i4);
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void eraseRange(int i, int i2, int i3) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        int i4 = i + i2;
        if (i4 > this.b) {
            throw new GeometryException("invalid_call");
        }
        float[] fArr = this.a;
        System.arraycopy(fArr, i4, fArr, i, i3 - i4);
        this.b -= i2;
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void readRange(int i, int i2, ByteBuffer byteBuffer, int i3, boolean z) {
        if (i < 0 || i2 < 0 || i3 < 0 || size() < i2 + i) {
            throw new IllegalArgumentException();
        }
        int sizeOf = NumberUtils.sizeOf((double) Utils.DOUBLE_EPSILON);
        if (byteBuffer.capacity() < (sizeOf * i2) + i3) {
            throw new IllegalArgumentException();
        }
        if (i2 == 0) {
            return;
        }
        if (!z) {
            i += i2 - 1;
        }
        int i4 = z ? 1 : -1;
        int i5 = 0;
        while (i5 < i2) {
            byteBuffer.putFloat(i3, this.a[i]);
            i += i4;
            i5++;
            i3 += sizeOf;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void reverseRange(int i, int i2, int i3) {
        if (this.m_bReadonly) {
            throw new GeometryException("invalid_call");
        }
        if (i3 < 1 || i2 % i3 != 0) {
            throw new GeometryException("invalid_call");
        }
        int i4 = i2 >> 1;
        int i5 = 0;
        while (i5 < i4) {
            i2 -= i3;
            for (int i6 = 0; i6 < i3; i6++) {
                float[] fArr = this.a;
                int i7 = i + i5 + i6;
                float f = fArr[i7];
                int i8 = i + i2 + i6;
                fArr[i7] = fArr[i8];
                fArr[i8] = f;
            }
            i5 += i3;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void setRange(double d, int i, int i2) {
        int i3;
        if (i < 0 || i2 < 0 || i < 0 || (i3 = i2 + i) > size()) {
            throw new IllegalArgumentException();
        }
        float f = (float) d;
        while (i < i3) {
            write(i, f);
            i++;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void writeRange(int i, int i2, AttributeStreamBase attributeStreamBase, int i3, boolean z, int i4) {
        if (i < 0 || i2 < 0 || i3 < 0) {
            throw new IllegalArgumentException();
        }
        if (!z && (i4 <= 0 || i2 % i4 != 0)) {
            throw new IllegalArgumentException();
        }
        AttributeStreamOfFloat attributeStreamOfFloat = (AttributeStreamOfFloat) attributeStreamBase;
        int i5 = i3 + i2;
        if (attributeStreamOfFloat.size() < i5) {
            throw new IllegalArgumentException();
        }
        if (i2 == 0) {
            return;
        }
        int i6 = i2 + i;
        if (size() < i6) {
            resize(i6);
        }
        if (attributeStreamBase == this) {
            a(i, i2, i3, z, i4);
            return;
        }
        int i7 = 0;
        if (z) {
            while (i7 < i2) {
                this.a[i] = attributeStreamOfFloat.a[i3];
                i++;
                i3++;
                i7++;
            }
            return;
        }
        int i8 = i5 - i4;
        if (i4 == 1) {
            while (i7 < i2) {
                this.a[i] = attributeStreamOfFloat.a[i8];
                i++;
                i8--;
                i7++;
            }
            return;
        }
        int i9 = i2 / i4;
        for (int i10 = 0; i10 < i9; i10++) {
            for (int i11 = 0; i11 < i4; i11++) {
                this.a[i + i11] = attributeStreamOfFloat.a[i8 + i11];
            }
            i += i4;
            i8 -= i4;
        }
    }

    private void a(int i, int i2, int i3, boolean z, int i4) {
        if (z && i == i3) {
            return;
        }
        if (i3 < i) {
            int i5 = (i3 + i2) - i4;
            int i6 = (i + i2) - i4;
            int i7 = i2 / 2;
            for (int i8 = 0; i8 < i7; i8++) {
                for (int i9 = 0; i9 < i4; i9++) {
                    float[] fArr = this.a;
                    fArr[i6 + i9] = fArr[i5 + i9];
                }
                i6 -= i4;
                i5 -= i4;
            }
        } else {
            int i10 = i;
            for (int i11 = 0; i11 < i2; i11++) {
                float[] fArr2 = this.a;
                fArr2[i10] = fArr2[i3];
                i10++;
                i3++;
            }
        }
        if (z) {
            return;
        }
        int i12 = (i + i2) - i4;
        int i13 = i2 / 2;
        for (int i14 = 0; i14 < i13; i14++) {
            for (int i15 = 0; i15 < i4; i15++) {
                float[] fArr3 = this.a;
                int i16 = i + i15;
                float f = fArr3[i16];
                int i17 = i12 + i15;
                fArr3[i16] = fArr3[i17];
                fArr3[i17] = f;
            }
            i += i4;
            i12 -= i4;
        }
    }

    @Override // com.esri.core.geometry.AttributeStreamBase
    public void writeRange(int i, int i2, ByteBuffer byteBuffer, int i3, boolean z) {
        if (i < 0 || i2 < 0 || i3 < 0) {
            throw new IllegalArgumentException();
        }
        int sizeOf = NumberUtils.sizeOf((double) Utils.DOUBLE_EPSILON);
        if (byteBuffer.capacity() < (sizeOf * i2) + i3) {
            throw new IllegalArgumentException();
        }
        if (i2 == 0) {
            return;
        }
        int i4 = i2 + i;
        if (size() < i4) {
            resize(i4);
        }
        if (!z) {
            i += i2 - 1;
        }
        int i5 = z ? 1 : -1;
        int i6 = 0;
        while (i6 < i2) {
            this.a[i] = byteBuffer.getFloat(i3);
            i += i5;
            i6++;
            i3 += sizeOf;
        }
    }
}
